package com.cafuc.base;

import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class DateTimeOperation {

    public void dateTimeTest() {
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calender = Calendar.getInstance();
        Date date = new Date();
        calender.setTime(date);
        System.out.println(ft.format(calender.getTime()));
        System.out.println(calender.get(Calendar.YEAR));
        System.out.println(calender.get(Calendar.MONTH)+1);
        System.out.println(calender.get(Calendar.DATE));

        Calendar ca = Calendar.getInstance();
        System.out.println(ca.get(Calendar.DATE));
        System.out.println(ca.getTimeInMillis());
        System.out.println(ft.format(ca.getTime()));

        // LocalDate, LocalTime, LocalDateTime
        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt.getYear());
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(dtf.format(ldt));

        Period period = Period.between(
//                LocalDate.of(2000, 1, 1),
                LocalDate.of(1980, Month.SEPTEMBER, 14),
                LocalDate.now());
        System.out.println(period.getDays());

        LocalDateTime birthday2 = LocalDateTime.of(1980, 9, 14, 11, 22, 33);
        Duration duration = Duration.between(birthday2, LocalDateTime.now());
        System.out.println(duration.toDays() + "-" + duration.toHours());
    }

    public static void main(String[] args) {
        DateTimeOperation dto = new DateTimeOperation();
        dto.dateTimeTest();

    }
}
